var isNewBean = false;
var jsTree = null;
var currentRYDM;
$(init);

function init() {
    $("div.left").height(($(window.document).height()) - 65);
    //人员树配置
    var setting = {
        async: {
            enable: true,
            url: ctx + "/xtwh/jggl/cshjgxx",
            autoParam: ["id=sjjgid"],
            dataFilter: function (treeId, parentNode, data) {
                return data.message;
            }
        },
        callback: {
            onClick: zTreeOnClick
        }
    };
    var zNodes = [
        {id: ssjgid, name: ssjgmc, open: false, isParent: true}
    ];
    //初始化人员树
    $.fn.zTree.init($("#orgTree"), setting, zNodes);

    $("#ryxxGrid").jqGrid(
            {
                url: ctx + '/common/extQuery?sqlid=ryxx',
                autowidth: true,
                height: (($(window.document).height()) - 140),
                datatype: 'json',
                colNames: ['人员代码', '人员名称', '所属机构', '',''],
                colModel: [
                    {name: 'username', index: 'username', width: 50, sortable: false},
                    {name: 'name', index: 'name', width: 50, sortable: false},
                    {name: 'orgmc', index: 'orgmc', width: 50, sortable: false},
                    {name: 'orgid', index: 'orgid', hidden: true},
                    {name: 'id', index: 'id', hidden: true}
                ],
                prmNames: {
                    rows: "limit"
                },
                jsonReader: {
                    root: "message.list",
                    page: "message.pageNumber",
                    total: "message.totalPage",
                    records: "message.totalRow"
                },
                treeReader: {
                    level_field: "level",
                    parent_id_field: "sjjgid",
                    leaf_field: "leaf",
                    expanded_field: "expanded"
                },
                multiselect: true,
                loadtext: "<img src='" + ctx + "/static/images/loading.gif'>&nbsp;&nbsp;拼命加载中...",
                rowNum: 50,
                rowList: [50, 100, 150],
                pager: '#ryxxPager',
                mtype: "POST",
                viewrecords: true,
                sortable: false
            });
	 //自适应屏幕
	$(window).resize(function(){
		$("#ryxxGrid").setGridWidth($(window).width()-250);
	});
}

/**
 * 人员树点击事件
 * @param {type} event
 * @param {type} treeId
 * @param {type} treeNode
 * @returns {undefined}
 */
function zTreeOnClick(event, treeId, treeNode) {
    if (treeId == "orgTree") {	
        var data = $("#searchForm").getFormJson();
        $("#ryxxGrid").setGridParam({postData: {"orgid": treeNode.id}}).trigger("reloadGrid", [{page: 1}]);
    } else if (treeId == "userTreeDemo") {
        $("#orgmc").val(treeNode.name);
        $("#orgid").val(treeNode.id);
    }
}

function doPush(){
	var arrUserid=$("#ryxxGrid").jqGrid("getGridParam","selarrrow");
	if(arrUserid.length==0){
		qyError("请选择要推送至的人员！");
		return;
	}
	var userids="";
	for(var i=0;i<arrUserid.length;i++){
		userids+=arrUserid[i];
		if(i<arrUserid.length-1){
			userids+=",";
		}
	}
	var result = doService(ctx+"/kjcj/push","userids",userids,"infoid",infoid);
	if(result){
		qyAlert("推送成功！",function(){
			parent.layer.closeAll();
		});
	}
}
